package edu.ucsd.ccdb.tagPopup.util;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JPanel;

import edu.ucsd.ccdb.DetailPanel;
import edu.ucsd.irods.IRODSFileString;

public class DetailViewAutoRefresh extends WindowAdapter {
	
	private JPanel detailView;
	private String username;
	private IRODSFileString file;
	private JFrame mainFrame;
	private Integer MPID;
	private String baseFolder;
	private List<String> clickedFile;
	
	public DetailViewAutoRefresh( JPanel detailView, String username, IRODSFileString file, JFrame mainFrame, Integer MPID,
									String baseFolder, List<String> clickedFile ) {
		
		this.detailView = detailView;
		this.username = username;
		this.file = file;
		this.mainFrame = mainFrame;
		this.MPID = MPID;
		this.baseFolder = baseFolder;
		this.clickedFile = clickedFile;
	}
	
	@Override 
	public void windowClosed (WindowEvent e) {
		System.out.println ("Dialog closed ");		
		refreshDetailView();
	}
	
	@Override
	public void windowClosing (WindowEvent e) {
		System.out.println ("Dialog closing");	
		refreshDetailView();
	}

	/**
	 * Refresh the detail view
	 */
	public void refreshDetailView () {
		
		detailView.removeAll();
		detailView.add(new DetailPanel(username, file, mainFrame, MPID, baseFolder, clickedFile ) );
		
//			detailView.add(new DetailPanel( username, file, mainFrame, MPID, pathTextField.getText(), listFileClicked ));
		
		detailView.validate();
		detailView.repaint();
	}
	
	/**
	 * Refresh detail view, static version
	 */
	public static void refreshDetailView_static ( JPanel detailView, String username, IRODSFileString file, JFrame mainFrame, Integer MPID,
			String baseFolder, List<String> clickedFile) {
		
		detailView.removeAll();
		detailView.add(new DetailPanel(username, file, mainFrame, MPID, baseFolder, clickedFile ) );
		
//			detailView.add(new DetailPanel( username, file, mainFrame, MPID, pathTextField.getText(), listFileClicked ));
		
		detailView.validate();
		detailView.repaint();
	}
}
